/*
 * @Author : Genustin
 * @Date   : 2012-05-31
 * 求数字和
 */
#include <iostream>
using namespace std;

int main()
{
	int num, a, b, c, d, e;
	cin >> num >> a >> b >> c >> d >> e;
	cout << (a<num?a:0) + (b<num?b:0) + (c<num?c:0) + (d<num?d:0) + (e<num?e:0) << endl;
	return 0;
}